package com.woniuxy.sales.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.sales.model.entity.Goods;
import com.woniuxy.sales.service.GoodsService;
import com.woniuxy.sales.untils.JwtTemplate;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/goods")
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private JwtTemplate jwtTemplate;

    @PostMapping("/findAll")
    @ApiOperation("查询全部")
    public ResponseEntity findAll(@RequestBody Map<String, Integer> params) {
        //获取页码和页面大小
        int pageNum = params.get("pageNum");
        int pageSize = params.get("pageSize");
        //调用业务层查询
        Page<Goods> page = goodsService.findAll(pageNum, pageSize);
        return ResponseEntity.ok(page);
    }


    @PostMapping("/findByType")
    @ApiOperation("根据类别查询")
    public ResponseEntity findByType(@RequestBody Map<String, Integer> params) {
        //获取页码和页面大小
        Integer pageNum = params.get("pageNum");
        Integer pageSize = params.get("pageSize");
        Integer type = params.get("type");
        //调用业务层查询
        Page<Goods> page = goodsService.findByType(pageNum, pageSize,type);
        return ResponseEntity.ok(page);
    }



    @GetMapping("/findById/{id}")
    @ApiOperation("通过ID查询商品")
    public ResponseEntity findById(@PathVariable("id") Integer id) {
        Goods goods = goodsService.findById(id);
        return ResponseEntity.ok(goods);
    }







}
